<template>
  <div class="mine">
    <div class="user"></div>
    <div class="option">
      <div class="user_info">
        <div class="img">
          <van-image
            fit="cover"
            :src="
              user.$state.userInfo?.userAvatarUrl
                ? host + user.$state.userInfo?.userAvatarUrl
                : s6
            "
          />
        </div>
        <div class="user_name">
          {{
            user.$state.userInfo?.nickName ||
            user.$state.userInfo?.contactNumber
          }}
        </div>
      </div>
      <div class="option_list">
        <div class="option_item" @click="toUserInfo">
          <img src="../../assets/img/shoucang.png" alt="" />
          <span>个人中心</span>
        </div>
        <div class="option_item" @click="toQueryList">
          <img src="../../assets/img/renwu.png" alt="" />
          <span>我的问卷</span>
        </div>
        <div class="option_item" @click="toQuestionList">
          <img src="../../assets/img/xinxi.png" alt="" />
          <span>我的服务</span>
        </div>
      </div>

      <div class="loginout" @click="login">
        {{ user.$state.token ? "退出登录" : "登录" }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import s6 from "../../assets/img/s6.jpg";
import useUserStore from "../../store/modules/user";
import { showConfirmDialog } from "vant";
let host = import.meta.env.VITE_APP_BASE_API;
let user = useUserStore();
let router = useRouter();
function toQueryList() {
  router.push("/queryList");
}
function toQuestionList() {
  router.push("/questionList");
}
function toUserInfo() {
  router.push("/userInfo");
}
// 获取用户信息
function getUserInfo() {
  user.getUserInfo();
}
getUserInfo();
function login() {
  if (user.$state.token) {
    showConfirmDialog({
      title: "提示",
      message: "是否退出登录",
    }).then(() => {
      user.loginOut();
    });
  } else {
    user.isShow(true);
  }
}
</script>

<style scoped lang="scss">
.mine {
  height: calc(100vh - 50px);
}

.user {
  height: 160px;
  border-bottom: 1px solid #eee;
  background: linear-gradient(
    to right bottom,
    var(--el-color-primaryop1),
    var(--el-color-primary)
  );
}

.option {
  background: white;
  position: relative;
  top: -20px;
  border-radius: 10px 10px 0 0;
  padding: 80px 14px 0 14px;

  // overflow: hidden;
  .user_info {
    text-align: center;
    position: absolute;
    top: -40px;
    left: 0;
    width: 100vw;

    .user_name {
      font-size: 16px;
      color: #333;
    }

    .van-image {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      overflow: hidden;
    }
  }
}

.option_list {
  box-shadow: 2px 2px 9px #ddd;
  border-radius: 10px;
  font-size: 16px;

  .option_item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    box-shadow: 2px 1px 1px #eee;
  }

  img {
    width: 36px;
    height: 36px;
    margin-right: 5px;
  }
}

.loginout {
  width: 200px;
  height: 40px;
  border-radius: 60px;
  line-height: 40px;
  margin: 0 auto;
  margin-top: 40px;
  color: white;
  text-align: center;
  background: var(--el-color-primary);
  font-size: 18px;
}
</style>
